package com.song.tools.trigger;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

/**
 * springbean工具类
 *
 * @author song tools
 * @since 2024-07-19
 */
@Component
public class SpringBeanUtil implements BeanFactoryAware {

    private static BeanFactory beanFactory;

    @Override
    public void setBeanFactory(@NonNull BeanFactory beanFactory) throws BeansException {
        SpringBeanUtil.beanFactory = beanFactory;
    }

    public static <T> T getByClass(Class<T> clazz) {
        return beanFactory.getBean(clazz);
    }
}
